/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package home.sockets.controller.providers;

import home.sockets.controller.parsers.IPParser;
import home.sockets.controller.parsers.Sock5Parser;
import home.sockets.controller.proxy.ProxyServer;
import home.sockets.controller.utils.SpringFactory;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 *
 * @author Evgeny
 */
public class ServersParser
{

    private String filename;
    
    public void Setfilename(String filename)
    {
        this.filename = filename;
    }
    
    public Collection<ProxyServer> getServersList(Collection<String> strings) 
    {
        Collection<ProxyServer> servers = new ArrayList();
        IPParser ipParser = SpringFactory.XML_INSTANCE.getBean(IPParser.class);
        Collection<? extends IPParser> parsers = Collections.singleton(ipParser);
        long be4 = System.currentTimeMillis();
        for (String addressStr : strings)
        {
            ProxyServer ps;
            for(IPParser parser: parsers)
            {
                ps = parser.tryParse(addressStr);
                if(ps != null)
                {
                    servers.add(ps);
                    break;
                }
            }
        }
        long after = System.currentTimeMillis();
        System.out.println("Time to parse servers " + (after - be4));
        return servers;
    }
    
}
